import React, { Fragment } from 'react';
import { Button } from 'antd';
import { connect } from 'dva';

// 修饰器只能放在类的前面
// @connect(({hooks})=>({
//     count:hooks.count
// }))

const reduxConponent = ({ count, dispatch }) => {
    const addCount = () => {
        dispatch({
            type: 'hooks/add',
            payload: {
                count: count + 1,
            },
        });
    };
    const reduceCount = () => {
        dispatch({
            type: 'hooks/reduce',
            payload: {
                count: count - 1,
            },
        });
    };

    return (
        <Fragment>
            <Button onClick={addCount}>加一</Button>
            <Button onClick={reduceCount}>减一</Button>
            <p>状态管理里面的count值: {count}</p>
        </Fragment>
    );
};
export default connect(({ hooks }) => ({
    count: hooks.count,
}))(reduxConponent);

// (p) => {
//     const { hooks } = p;
//     return {
//         count: hooks.count,
//     }
// }
